package com.qdu.dao.impl;

import com.qdu.dao.BaseDao;
import com.qdu.util.DatabaseUtil;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;

/**
 * BaseDao的实现类
 *
 * @author Lenovo
 */
public class BaseDaoImpl implements BaseDao{

    @Override
    public int executeUpdate(String sql, Object... params) {
        
            Connection con=null;
            PreparedStatement ps=null;
            int rows=0;
            
        try {
            con=DatabaseUtil.getConnection();
            ps=con.prepareStatement(sql);
            for(int i=0;i<params.length;i++)
            {
                ps.setObject(i+1,params[i]);
            }
            rows=ps.executeUpdate();
            
        } catch (SQLException ex) {
            ex.printStackTrace();
        }finally{
            DatabaseUtil.close(null, ps, con);
        }
        return rows;
    }

}
